//CFETS Quote, CFETS数据
#pragma once

#include <string>
#include <map>
#include <mutex>
#include "BondInfo.h"
#include "qbprotocol/include/SSCFETSModel.h"

/////////////////////////////////////////////////////////////////////////////////////////////
//CFETS报价 add by lancezhao 20140819
struct S_BONDLIB_EXPORT CFETSQUOTE{
public:
	tBondKey		m_sBondKey;					// 债券编码
	//tBondCode		m_sBondCode;				// 证券代码,以'\0'结尾
	char		    m_sListedMarket[8];			// 市场1
	char			m_Symbol[4];				// 1:bid, -1: ask，成交日线可不用本字段，Write操作时有效，Read操作时无效

	char			m_BidPriceYield[12];		// bid收益率
	char			m_BidPriceClean[12];		// bid净价
	char			m_BidPriceFull[12];			// bid全价
	char			m_BidVol[32];				// bid量
	char		    m_bidVolDescription[128];	//量备注
	time_t			m_bidTime;
	int				m_bidversion;
	char			m_OfrPriceYield[12];		// ofr收益率
	char			m_OfrPriceClean[12];		// ofr净价
	char			m_OfrPriceFull[12];			// ofr全价
	char			m_OfrVol[32];				// ofr量
	char		    m_ofrVolDescription[128];	//
	time_t			m_ofrTime;
	int				m_ofrversion;

	time_t	        m_time;						// 交易时间
	std::string		m_BidCompanyName;			// bid方公司ID
	std::string	    m_OfrCompanyName;			// ofr方公司ID

	CFETSQUOTE();
	virtual ~CFETSQUOTE();
	void Clear();
	CFETSQUOTE& operator = (const CFETSQUOTE& one);
};

class S_BONDLIB_EXPORT CCFETSQuote
{
public:
	enum CFETSQUOTETYPE{
		QINVALID = -1,
		BESTPRICE = 0,
		MARKETMAKER = 1,
		XBOND = 2,
		QMAX = 3
	};
	std::map<CFETSQUOTETYPE, CFETSQUOTE> m_map;	//nType, cfetsquote //nType = 0 最优报价哦，= 1 点击成交报价，= 2 X-BOND报价
};

class S_BONDLIB_EXPORT CCFETSQuoteRep
{
public:
	CCFETSQuoteRep();
	virtual ~CCFETSQuoteRep();
	bool	Clear( );

	int		GetSize()const ;
	int		GetBytes(int mode=0)const;
	int		GetItemSize()const{ return sizeof(CFETSQUOTE); }
	const char* GetName()const;

	bool	InsertQuote(CCFETSQuote::CFETSQUOTETYPE, const CFETSQUOTE&);
	bool	GetQuoteByKey(CCFETSQuote::CFETSQUOTETYPE, CFETSQUOTE&); //nType = 0 最优报价哦，= 1 点击成交报价，= 2 X-BOND报价

protected:
	CCFETSQuote				m_RepMap;
	std::mutex		m_lock;//TODO spin?
};

class S_BONDLIB_EXPORT CCFETSDealQuote
{
public:
	std::map<int, xQBCFETSDealAllUnit> m_map;	//为适配QuoteRepManager， key===1
};

class S_BONDLIB_EXPORT CCFETSDealQuoteRep
{
public:
	CCFETSDealQuoteRep();
	virtual ~CCFETSDealQuoteRep();
	bool	Clear();
	
	bool	InsertDealQuote(const xQBCFETSDealAllUnit&);
	bool	GetDealQuote(xQBCFETSDealAllUnit&);
public://调试用
	int		GetSize()const;
	int		GetBytes(int mode=0)const;
	int		GetItemSize()const;
	const char* GetName()const;
protected:
	CCFETSDealQuote			m_RepMap;
	std::mutex		m_lock;
};

